const axios = require('axios');

async function testLogin() {
  try {
    console.log('开始测试登录API...');
    console.log('API地址: http://localhost:5038/api/Man/Login');
    
    const loginData = {
      username: '黑泽',
      password: '123456',
      verificationCode: 'TEST' // 测试时使用固定验证码
    };
    
    console.log('发送的登录数据:', loginData);
    
    const response = await axios.post('http://localhost:5038/api/Man/Login', loginData, {
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
      },
      timeout: 10000
    });
    
    console.log('✅ 请求成功!');
    console.log('响应状态码:', response.status);
    console.log('响应数据:', response.data);
    
    if (response.data && (response.data.success || response.data.code === 200 || response.status === 200)) {
      console.log('✅ 登录成功!');
    } else {
      console.log('❌ 登录失败:', response.data?.message || response.data?.msg);
    }
    
  } catch (error) {
    console.log('❌ 请求失败!');
    console.log('错误类型:', error.code);
    console.log('错误消息:', error.message);
    
    if (error.response) {
      console.log('响应状态码:', error.response.status);
      console.log('响应数据:', error.response.data);
    }
    
    if (error.code === 'ECONNREFUSED') {
      console.log('❌ 无法连接到服务器，请确认服务器是否在 http://localhost:5038 运行');
    } else if (error.code === 'ECONNABORTED') {
      console.log('❌ 请求超时');
    }
  }
}

// 运行测试
testLogin(); 